package com.lcq.study.pdf.jasper;

import net.sf.jasperreports.engine.DefaultJasperReportsContext;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;

import java.util.List;

/**
 * @ClassName JasperUtils
 * @Description
 * @Author lichuanqi
 * @Date 2022/6/25 18:15
 * @Version 1.0
 **/
public class JasperUtils {
    private JasperUtils(){}

    public static void exportPages(String destFile, List<JasperPrint> jasperPrintList) throws JRException {
        JRPdfExporter exporter = new JRPdfExporter(DefaultJasperReportsContext.getInstance());
        SimpleExporterInput simpleExporterInput = SimpleExporterInput.getInstance(jasperPrintList);
        exporter.setExporterInput(simpleExporterInput);
        exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
        exporter.exportReport();
    }
}
